module(..., package.seeall)

--====================================================================--
-- POP UP: MYSTATS POPUP
--====================================================================--

--[[

******************
 - INFORMATION
******************

  - Sample scene.

--]]

--import the scrolling classes

local imgPath = "images/"

local widget = require "widget"
-- Set the widget theme
widget.setTheme( "theme_ios" )


new = function ()
	
	------------------
	-- Groups
	------------------
	
	local localGroup = display.newGroup()
	
	------------------
	-- Display Objects
	------------------
	
	local w, h = display.contentWidth, display.contentHeight
	local background = display.newImage( "background3.png" )
	background.xScale = 0.94
	background.yScale = 0.8
	background.alpha = 0.95
	
	--close button
	local btBatsut = function ( event )
		if event.phase == "release" then
			director:closePopUp()
		end
	end

	local btBatsu = ui.newButton{
					default = imgPath .. "cross_yellow_64.png",
					over = imgPath .. "cross_green_64.png",
					onEvent = btBatsut,
					id = "btBatsu"
	}
	btBatsu.x, btBatsu.y = 295,20

	--eo close button
	
	--popup header
	local headerBdr = display.newRect( 10, 0, display.contentWidth-20, 30 )
	headerBdr.strokeWidth = 1
	headerBdr:setFillColor(90, 90, 90)
	headerBdr:setStrokeColor(70, 70, 70)
	
	--popup title
	local popupTitle = display.newText( "Settings", 120, 5, native.systemFontBold, 20 )

	------------------
	-- Slider
	------------------
			--setting for BGM,Sound Effect,Notification (on/off)
	
	-- Create a label, slider, and slider listener
	local sliderResult = display.newEmbossedText( headerGroup, "Slider at 50%", 0, 0, native.systemFontBold, 18 )
	sliderResult:setTextColor( 0 )
	sliderResult:setReferencePoint( display.CenterReferencePoint )
	sliderResult.x = 160
	sliderResult.y = 120
	
	-- slider listener function
	local function sliderListener( event )
		local val = "Slider at " .. event.value .. "%"
		sliderResult:setText( val )
		sliderResult:setReferencePoint( display.CenterReferencePoint )
		sliderResult.x = 160
		sliderResult.y = 120
		audio.setVolume(event.value/100, { channel=1 })
	end
	
	-- Create a default slider (using widget.setTheme)
	local slider = widget.newSlider
	{
		left = 50,
		top = 100,
		listener = sliderListener
	}
	slider:setValue( 25 )
	
	-- Create a on/off switch
	local function onSwitchPress( event )
		local switch = event.target
		
		-- Print whether or not the switch is on
		print( switch.id, "is on?:", switch.isOn )
		
	end
	local onOffSwitch = widget.newSwitch
	{
		left = 100,
		top = 200,
		initialSwitchState = true,
		--onPress = onSwitchPress,
		onRelease = onSwitchPress
	}
	
	backgroundMusic = audio.loadStream("sounds/harlem_shake_ring.mp3")
	audio.setVolume(0.5, { channel=1 })
	backgroundMusicChannel = audio.play( backgroundMusic, { channel=1, loops=-1, fadein=5000 }  )
    aa = audio.getVolume()
	channel1MaxVolume = audio.getMaxVolume( { channel=1 } )
    print("volume: ", aa)
	--audio.getVolume()
    --audio.setVolume()
	--backgroundMusic = audio.loadStream("backgroundMusic.m4a")
	--narrationSpeech = audio.loadStream("narrationSpeech.wav")
	--laserSound = audio.loadSound("laserBlast.wav")
		
	--popup window group
	local headerGroup = display.newGroup();
	headerGroup.x = 0;
	headerGroup.y = 50;
	headerGroup:insert(headerBdr)
	headerGroup:insert(popupTitle)
	headerGroup:insert(btBatsu)
	headerGroup:insert( slider )
	headerGroup:insert( onOffSwitch )
	headerGroup.xScale = 1;
	headerGroup.yScale = 1;			
	--eo popup window group

	--tirana
	--local potion = display.newImage( imgPath .. "potion_128.png" )
	--potion.xScale = 2.0
	--potion.yScale = 2.0
	--potion.x = 250
	--potion.y = 400
	---potion.rotation = -70
	--potion.rotation = 0
	--tirana.xScale = -0.4


	------------------
	-- Listeners
	------------------
	
	local touched = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	
	local closed = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	

	
	--====================================================================--
	-- INITIALIZE
	--====================================================================--
	
	local function initVars ()
		
		------------------
		-- Inserts
		------------------
		
		localGroup:insert( background )
		--localGroup:insert( potion )
		localGroup:insert( headerGroup )
		--localGroup:insert( scroller )
		--localGroup:insert( btBatsu )
		
		
		------------------
		-- Positions
		------------------
		
		--
		
		------------------
		-- Colors
		------------------
		
		--title:setTextColor( 255,255,255 )
		
		------------------
		-- Listeners
		------------------
		
		--background:addEventListener( "touch" , touched )
		
	end
	
	------------------
	-- Initiate variables
	------------------
	
	initVars()
	
	------------------
	-- MUST return a display.newGroup()
	------------------
	
	return localGroup
	
end
